home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / alib10.zip / TEMPLATE.ASM < prev   
Assembly Source File  |  1994-03-21  |  4KB  |  137 lines

  1. ;**************************** TEMPLATE.ASM **********************************
  2. PAGE  66,132
  3. comment 
  4.                              TEMPLATE.ASM
  5.                              ------------
  6.  
  7.      Purpose:
  8.      --------
  9.  
  10.      TEMPLATE.ASM is a skeleton assembly language program which
  11.      can be used as the basis to start a new program.
  12.  
  13.      Using TEMPLATE.ASM
  14.      ------------------
  15.  
  16.      The setup in TEMPLATE should work for most programs without using
  17.      alot of memory.  If no floating point variables are used then
  18.      some memory can be saved by modifying the call to library_open
  19.      to specify zero floating variables.  Next, add code to the
  20.      area of TEMPLATE.ASM which indicates the main body of the program
  21.      goes here.
  22.      
  23.      TEMPLATE.ASM was tested with MASM and OPTASM, but any assembler
  24.      should work.  
  25.  
  26.      Compiling
  27.      ---------
  28.  
  29.      The following commands can be used to compile TEMPLATE and
  30.      create TEMPLATE.EXE:
  31.         masm TEMPLATE;
  32.         link TEMPLATE,TEMPLATE,,alib.lib;
  33.  
  34. 
  35.  
  36.      
  37.  
  38. ; Sample template for creating programs using ALIB.LIB
  39. ;
  40.     include    mac.inc
  41.     include    common.inc
  42. ;-----------------------------------------------------------------------------
  43.     extrn    library_setup:far
  44.     extrn    library_terminate:far    
  45.     extrn    lib_error_handler:far
  46. ;------------------------------------------------------------------------------
  47. code        segment para public 'CODE'
  48.         assume    cs:code, ds:code
  49. ;-----------------------------------------------------------------------------
  50. ;
  51. pspseg        dw    0            ;Program Segment Prefix
  52.         dw    200 dup (0)        ;stack
  53. stack_        dw    0
  54. ;-----------------------------------------------------------------------------
  55. start:
  56.     cli
  57.     mov    cs:pspseg,es    ;save PSP segment
  58.     mov    ax,cs        ;get CODE segment
  59.     mov    ss,ax
  60.     mov    ds,ax
  61.     mov    es,ax
  62.     mov    sp,offset stack_
  63.     sti
  64.     
  65. ; next, release memory beyond the end of the program
  66. ; The  definition for ZSEG marks the
  67. ; end of the program's code, data and stack area.
  68. ; When linking be sure ZSEG is at the end of the program.
  69.  
  70.     mov    ax,zseg
  71.  
  72.     mov    bx,cs:pspseg        ;
  73.     mov    es,bx
  74.     sub    bx,ax
  75.     neg    bx            ; size of program in paragraphs
  76.     mov    ah,4Ah            ; resize memory block
  77.     int    21h
  78.  
  79.     mov    ax,cs
  80.     mov    es,ax
  81. ;
  82. ; check if enough memory free to run program
  83. ;
  84.     mov    ax,pspseg        ;pass psp segment to setup
  85.     mov    bx,8            ;number of floating point variables
  86.     call    library_setup
  87.     cmp    ax,128            ;check if 128k of memory is available
  88.     jae    got_enough_mem        ;jmp if 128k of memory avail
  89.     mov    al,7
  90.     mov    ah,fatal_return
  91.     call    lib_error_handler
  92.     jmp    exit2
  93.     
  94. got_enough_mem:
  95.     
  96. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  97. ; Ctrl+Alt+Del key combinations
  98.  
  99. ;    call    BREAK_KEY_INTERCEPT    ;optional
  100.  
  101.  
  102. ;  add main body of program here ............
  103.  
  104.  
  105.     
  106.  
  107. ; normal program exit
  108. ;
  109. exit1:    
  110. ;
  111. ; de-activate the Ctrl+Break trap
  112. ;    call    BREAK_KEY_RESTORE    ;needed only if BREAK_KEY_INTERCEPT called
  113.  
  114. exit2:    mov    ax,0
  115.     call    library_terminate
  116.     mov    ax,4C00h
  117.     int    21h
  118. ;------------------------
  119. code        ends
  120. ;-------------------------------------------------------------------------
  121. ;
  122. ; This segment definition is needed so linker will put the LIBSEG here
  123. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  124. ; work correctly.
  125. ;
  126. LIBSEG           segment byte public 'LIB'
  127. LIBSEG    ENDS
  128. ;-------------------------------------------------------------------------
  129. ; zseg must be at the end of the program for memory allocation from
  130. ; DOS.
  131. ;
  132. zseg    segment    para public 'ZZ'
  133.  
  134. zseg    ends
  135.  
  136.         end    start
  137.